<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>收货地址管理 - 超市系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link rel="icon" href="/photo/Profile picture/log.ico" type="image/x-icon">
    <style>
        :root {
            --primary: #3498db;
            --primary-dark: #2980b9;
            --primary-light: #e1f0fa;
            --secondary: #2c3e50;
            --accent: #16a085;
            --light: #f8f9fa;
            --dark: #2c3e50;
            --gray: #95a5a6;
            --light-gray: #eaeff2;
            --border: #dee2e6;
            --success: #27ae60;
            --danger: #e74c3c;
            --warning: #f39c12;
            --card-bg: #ffffff;
            --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
            --transition: all 0.3s ease;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: linear-gradient(135deg, #f0f5f9 0%, #e4edf5 100%);
            color: var(--dark);
            min-height: 100vh;
            padding: 20px;
        }

        .addresses-container {
            max-width: 1200px;
            margin: 20px auto;
            padding: 30px;
            background-color: var(--card-bg);
            border-radius: 12px;
            box-shadow: var(--shadow);
            position: relative;
            overflow: hidden;
        }

        .addresses-container::before {
            content: '';
            position: absolute;
            top: 0;
            right: 0;
            width: 250px;
            height: 250px;
            background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
            border-radius: 0 0 0 100%;
            z-index: 0;
        }

        .addresses-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 1px solid var(--border);
            position: relative;
            z-index: 1;
        }

        .addresses-header h2 {
            color: var(--dark);
            font-size: 28px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .addresses-header h2 i {
            color: var(--primary);
        }

        .add-address-button {
            background: var(--primary);
            color: white;
            padding: 12px 24px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 500;
            transition: var(--transition);
            display: flex;
            align-items: center;
            gap: 8px;
            box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
        }

        .add-address-button:hover {
            background: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: 0 6px 12px rgba(52, 152, 219, 0.4);
        }

        .address-list {
            border-radius: 8px;
            overflow: hidden;
            position: relative;
            z-index: 1;
        }

        .address-list table {
            width: 100%;
            border-collapse: separate;
            border-spacing: 0;
            background: var(--card-bg);
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
        }

        .address-list th {
            background: var(--primary-light);
            color: var(--dark);
            font-weight: 600;
            padding: 16px 20px;
            text-align: left;
            border-bottom: 2px solid var(--primary);
        }

        .address-list td {
            padding: 16px 20px;
            border-bottom: 1px solid var(--border);
            transition: var(--transition);
        }

        .address-list tr:last-child td {
            border-bottom: none;
        }

        .address-list tr:hover td {
            background: var(--light);
        }

        .action-btn {
            padding: 8px 16px;
            margin-right: 8px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            gap: 6px;
        }

        .edit-btn {
            background: var(--light-gray);
            color: var(--dark);
            border: 1px solid var(--border);
        }

        .edit-btn:hover {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        .delete-btn {
            background: var(--light-gray);
            color: var(--dark);
            border: 1px solid var(--border);
        }

        .delete-btn:hover {
            background: var(--danger);
            color: white;
            border-color: var(--danger);
        }

        .default-address {
            background: rgba(52, 152, 219, 0.1);
            color: var(--primary-dark);
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 13px;
            font-weight: 500;
            display: inline-flex;
            align-items: center;
            gap: 6px;
        }

        .set-default-btn {
            padding: 8px 16px;
            border-radius: 6px;
            border: none;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            transition: var(--transition);
            background: var(--light-gray);
            color: var(--dark);
            display: inline-flex;
            align-items: center;
            gap: 6px;
        }

        .set-default-btn:hover {
            background: var(--primary);
            color: white;
        }

        /* 模态框样式 */
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.5);
            justify-content: center;
            align-items: center;
        }

        .modal-content {
            background-color: var(--card-bg);
            margin: auto;
            padding: 30px;
            border-radius: 12px;
            width: 90%;
            max-width: 600px;
            position: relative;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            animation: modalAppear 0.4s ease;
        }

        @keyframes modalAppear {
            from { transform: translateY(30px); opacity: 0; }
            to { transform: translateY(0); opacity: 1; }
        }

        .close {
            position: absolute;
            top: 20px;
            right: 20px;
            color: var(--gray);
            font-size: 28px;
            font-weight: bold;
            cursor: pointer;
            transition: var(--transition);
            z-index: 10;
        }

        .close:hover {
            color: var(--primary-dark);
            transform: rotate(90deg);
        }

        .modal-header {
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 1px solid var(--border);
        }

        .modal-header h3 {
            font-size: 22px;
            color: var(--dark);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .delivery-location {
            background: var(--primary-light);
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 25px;
            font-size: 15px;
            color: var(--dark);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .delivery-location .location {
            font-weight: 600;
            color: var(--primary-dark);
        }

        .delivery-location .change-location {
            color: var(--primary);
            text-decoration: none;
            font-weight: 500;
            margin-left: auto;
        }

        .delivery-location .change-location:hover {
            text-decoration: underline;
        }

        .info-form .form-group {
            margin-bottom: 20px;
        }

        .info-form label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--dark);
            display: flex;
            align-items: center;
            gap: 5px;
        }

        .required {
            color: var(--danger);
            font-weight: bold;
        }

        .address-selects {
            display: flex;
            gap: 12px;
            margin-bottom: 8px;
        }

        .address-selects select {
            flex: 1;
            padding: 12px 15px;
            border: 1px solid var(--border);
            border-radius: 8px;
            font-size: 15px;
            color: var(--dark);
            background-color: white;
            transition: var(--transition);
            appearance: none;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='%23333'%3E%3Cpath d='M6 8L0 0h12L6 8z'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 15px center;
            background-size: 12px;
        }

        .address-selects select:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
        }

        textarea, input[type="text"] {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid var(--border);
            border-radius: 8px;
            font-size: 15px;
            color: var(--dark);
            background-color: white;
            transition: var(--transition);
        }

        textarea:focus, input[type="text"]:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
        }

        textarea {
            min-height: 100px;
            resize: vertical;
        }

        .phone-group {
            display: flex;
            gap: 12px;
            align-items: center;
        }

        .phone-group select {
            width: 140px;
            padding: 12px 15px;
            border: 1px solid var(--border);
            border-radius: 8px;
            font-size: 15px;
            color: var(--dark);
            background-color: white;
        }

        .phone-group input {
            flex: 1;
        }

        .form-group input[type="checkbox"] {
            margin-right: 10px;
            width: 18px;
            height: 18px;
            accent-color: var(--primary);
        }

        .form-actions {
            margin-top: 30px;
            text-align: center;
        }

        .save-address-btn {
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 8px;
            padding: 14px 50px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
            box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
        }

        .save-address-btn:hover {
            background: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(52, 152, 219, 0.4);
        }

        /* 删除确认弹窗 */
        #deleteConfirmModal .modal-content {
            width: 350px;
            padding: 30px;
            text-align: center;
        }

        #deleteConfirmModal .modal-body {
            padding: 0;
        }

        #deleteConfirmModal .modal-body div:first-child {
            font-size: 18px;
            margin-bottom: 30px;
            color: var(--dark);
        }

        #deleteConfirmModal .modal-body div:last-child {
            display: flex;
            gap: 15px;
            justify-content: center;
        }

        #deleteConfirmModal button {
            flex: 1;
            padding: 12px 0;
            border-radius: 8px;
            border: none;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
        }

        #deleteConfirmModal button:first-child {
            background: var(--light-gray);
            color: var(--dark);
        }

        #deleteConfirmModal button:first-child:hover {
            background: #d1d9e0;
        }

        #deleteConfirmModal button:last-child {
            background: var(--danger);
            color: white;
            box-shadow: 0 4px 8px rgba(231, 76, 60, 0.3);
        }

        #deleteConfirmModal button:last-child:hover {
            background: #c0392b;
            transform: translateY(-2px);
            box-shadow: 0 6px 12px rgba(231, 76, 60, 0.4);
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .addresses-container {
                padding: 25px;
            }
            
            .address-list th, 
            .address-list td {
                padding: 14px 16px;
                font-size: 14px;
            }
            
            .address-list .action-btn {
                padding: 7px 12px;
                font-size: 13px;
            }
        }

        @media (max-width: 768px) {
            body {
                padding: 15px;
            }
            
            .addresses-container {
                padding: 20px;
            }
            
            .addresses-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }
            
            .address-list {
                overflow-x: auto;
            }
            
            .address-list table {
                min-width: 700px;
            }
            
            .modal-content {
                padding: 25px;
            }
            
            .address-selects {
                flex-direction: column;
                gap: 10px;
            }
        }

        @media (max-width: 576px) {
            .addresses-container {
                padding: 15px;
            }
            
            .addresses-header h2 {
                font-size: 24px;
            }
            
            .add-address-button {
                width: 100%;
                justify-content: center;
            }
            
            .modal-content {
                padding: 20px;
            }
            
            .phone-group {
                flex-direction: column;
                align-items: stretch;
            }
            
            #deleteConfirmModal .modal-content {
                width: 90%;
            }
        }
    </style>
</head>
<body>
    <main id="app">
        <div class="addresses-container">
            <div class="addresses-header">
                <h2><i class="fas fa-map-marker-alt"></i> 我的收货地址</h2>
                <button class="add-address-button" @click="openNewAddress">
                    <i class="fas fa-plus-circle"></i> 添加地址
                </button>
            </div>
            <div class="address-list">
                <table>
                    <thead>
                        <tr>
                            <th>收货人</th>
                            <th>电话/手机</th>
                            <th>所在地区</th>
                            <th>详细地址</th>
                            <th>操作</th>
                            <th>设置</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="addr in addresses" :key="addr.addressId">
                            <td>{{ addr.name }}</td>
                            <td>{{ addr.phone }}</td>
                            <td>{{ addr.region }}</td>
                            <td>{{ addr.address }}</td>
                            <td>
                                <button class="action-btn edit-btn" @click="editAddress(addr)">
                                    <i class="fas fa-edit"></i> 修改
                                </button>
                                <button class="action-btn delete-btn" @click="confirmDelete(addr)">
                                    <i class="fas fa-trash-alt"></i> 删除
                                </button>
                            </td>
                            <td>
                                <span v-if="addr.isDefault" class="default-address">
                                    <i class="fas fa-check-circle"></i> 默认地址
                                </span>
                                <button v-else class="set-default-btn" @click="setDefault(addr.addressId)">
                                    <i class="fas fa-star"></i> 设为默认
                                </button>
                            </td>
                        </tr>
                        <tr v-if="addresses.length === 0">
                            <td colspan="6" style="text-align:center; padding: 40px; color: var(--gray);">
                                <i class="fas fa-inbox" style="font-size: 48px; margin-bottom: 15px; display: block;"></i>
                                暂无收货地址
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- 新建/编辑地址模态框 -->
        <div id="newAddressModal" class="modal" :style="{ display: showModal ? 'block' : 'none' }">
            <div class="modal-content">
                <span class="close" @click="showModal=false">&times;</span>
                <div class="modal-header">
                    <h3><i :class="editMode ? 'fas fa-edit' : 'fas fa-plus-circle'"></i> {{ editMode ? '修改地址' : '新建地址' }}</h3>
                </div>
                <div class="modal-body">
                    <div class="delivery-location">
                        <i class="fas fa-globe-asia"></i>
                        <span>当前配送至</span>
                        <span class="location">中国大陆</span>
                        <a href="#" class="change-location">切换地区</a>
                    </div>
                    <form class="info-form">
                        <div class="form-group">
                            <label for="addressInfo">
                                <span class="required">*</span>地址信息:
                            </label>
                            <div class="address-selects">
                                <select id="provinceSelect" v-model="currentAddress.province" @change="onProvinceChange">
                                    <option value="">请选择省份</option>
                                    <option v-for="p in provinces" :key="p" :value="p">{{ p }}</option>
                                </select>
                                <select id="citySelect" v-model="currentAddress.city" @change="onCityChange">
                                    <option value="">请选择城市</option>
                                    <option v-for="c in cities" :key="c" :value="c">{{ c }}</option>
                                </select>
                                <select id="districtSelect" v-model="currentAddress.district">
                                    <option value="">请选择区域</option>
                                    <option v-for="d in districts" :key="d" :value="d">{{ d }}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="detailedAddress">
                                <span class="required">*</span>详细地址:
                            </label>
                            <textarea id="detailedAddress" v-model="currentAddress.address" 
                                placeholder="请输入详细地址信息，如道路、门牌号、小区、楼栋号、单元等信息"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="recipientName">
                                <span class="required">*</span>收货人姓名:
                            </label>
                            <input type="text" id="recipientName" v-model="currentAddress.name" 
                                placeholder="长度不超过25个字符">
                        </div>
                        <div class="form-group">
                            <label for="phoneNumber">
                                <span class="required">*</span>手机号码:
                            </label>
                            <div class="phone-group">
                            
                                <input type="text" id="phoneNumber" v-model="currentAddress.phone" 
                                    placeholder="请输入您的手机号码">
                            </div>
                        </div>
                        <div class="form-group">
                            <label>
                                <input type="checkbox" id="setDefaultAddress" v-model="currentAddress.isDefault">
                                设置为默认收货地址
                            </label>
                        </div>
                        <div class="form-actions">
                            <button class="save-address-btn" type="button" @click="saveAddress">
                                <i class="fas fa-save"></i> 保存地址
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <!-- 删除确认弹窗 -->
        <div id="deleteConfirmModal" class="modal" v-if="showDeleteModal">
            <div class="modal-content">
                <span class="close" @click="showDeleteModal=false">&times;</span>
                <div class="modal-body">
                    <div>
                        <i class="fas fa-exclamation-triangle" style="font-size: 48px; color: var(--danger); margin-bottom: 20px;"></i>
                        <div style="font-size: 18px; margin-bottom: 10px;">确认删除该条地址？</div>
                        <div style="color: var(--gray); margin-bottom: 30px;">此操作不可撤销</div>
                    </div>
                    <div>
                        <button @click="showDeleteModal=false">取消</button>
                        <button @click="doDelete">确认删除</button>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.min.js"></script>
    <script src="js/addresses.js">
      
    </script>
</body>
</html>